﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ReverseWords
{
    class Program
    {
        static void Main(string[] args)
        {
            String text =
             "Keywords are predefined reserved, identifiers that have special meanings to the compiler.";
            string splitPattern = @"[/ |/.]+";
            string[] words = Regex.Split(text, splitPattern);
            StringBuilder reverseSentence = new StringBuilder();
            reverseSentence.Append((words[words.Length-2])[0].ToString().ToUpper());
            for (int i = 1; i < words[words.Length-2].Length; i++)
            {
                reverseSentence.Append(words[words.Length-2][i]);
            }
            reverseSentence.Append(" ");
            for (int i = words.Length-3; i >= 0; i--)
            {
                if (words[i] != "")
                {

                    if (words[i][words[i].Length-1] != ',')
                    {
                        reverseSentence.Append(words[i].ToLower() + " ");
                    }

                    else
                    {
                        reverseSentence.Append(", ");
                        for (int j = 0; j < words[i].Length-1; j++)
                        {
                            reverseSentence.Append(words[i][j]);
                        }
                        reverseSentence.Append(" ");
                    }
                }
                
            }
            reverseSentence.Append(".");
            Console.WriteLine(reverseSentence);
        }
    }
}
